package com.kun.service.impl;

import com.kun.entity.Blogger;
import com.kun.mapper.BloggerMapper;
import com.kun.service.BloggerService;
import com.kun.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author SunKun
 * @since 2021-06-14
 */
@Service
public class BloggerServiceImpl implements BloggerService {
    @Autowired
    BloggerMapper bloggerMapper;

    /**
     * 查询该博主
     * @param blogger
     * @return
     * @throws Exception
     */
    @Override
    public Blogger queryBlogger(Blogger blogger) throws RuntimeException {
        Blogger byUsername = bloggerMapper.queryBloggerByUsername(blogger.getUsername());
        if(byUsername != null){
            if(MD5Utils.getSaltVerifyMD5(blogger.getPassword(),byUsername.getPassword())){
                return byUsername;
            }
            throw new RuntimeException("该密码不正确!");
        }
        throw new RuntimeException("该用户不存在!");
    }
}
